package com.xiaozhou.function;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author shhzhou
 * @description:
 * @date 2024/10/31 11:38
 */
@Service
public class FunctionManager {

    private final ApplicationContext applicationContext;

    @Autowired
    public FunctionManager(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    public String callFunction(String functionName, Object args) {

        IFunction function = applicationContext.getBean(functionName, IFunction.class);
        if (function != null) {
            return function.execute(args);
        } else {
            throw new IllegalArgumentException("Function not found: " + functionName);
        }


    }


}
